package com.ecommerce.dddmodules.shippingcontext.model;

import java.util.List;
/**
 * @packageName: shippingcontext.model（发货上下文.领域包）
 * @className: Parcel(包裹领域)
 * @description: 围绕此包裹领域展开业务
 * @author: luds
 * @version: v1.0
 * @date: 2021-04/01
 */
public class Parcel {
	/**
	 * 订单ID
	 */
	private int orderId;
	/**
	 * 送货地址
	 */
	private String address;
	/**
	 * 跟踪号码
	 */
	private String trackingId;
	/**
	 * 包裹项目明细
	 */
	private List<PackageItem> packageItems;

	/**
	 * 由订单ID、送货地址、包裹项目明细构造包裹
	 * @param orderId 订单ID
	 * @param address 送货地址
	 * @param packageItems 包裹项目明细
	 */
	public Parcel(int orderId, String address, List<PackageItem> packageItems) {
		this.orderId = orderId;
		this.address = address;
		this.packageItems = packageItems;
	}

	/**
	 * 计算总重量
	 * @return 总重量
	 */
	public float calculateTotalWeight() {
		return packageItems.stream().map(PackageItem::getWeight)
				.reduce(0F, Float::sum);
	}

	/**
	 * 是否可纳税
	 * @return 返回是否可纳税
	 */
	public boolean isTaxable() {
		// 通过估值计算，大于100时可纳税；否则不用纳税
		return calculateEstimatedValue() > 100;
	}

	/**
	 * 计算估值
	 * @return 返回估值
	 */
	public float calculateEstimatedValue() {
		return packageItems.stream().map(PackageItem::getWeight)
				.reduce(0F, Float::sum);
	}

	/**
	 * 获取订单ID
	 * @return 返回订单ID
	 */
	public int getOrderId() {
		return orderId;
	}

	/**
	 * 设置订单ID
	 * @param orderId 订单ID
	 */
	public void setOrderId(int orderId) {
		this.orderId = orderId;
	}

	/**
	 * 获取跟踪号码
	 * @return 返回跟踪号码
	 */
	public String getTrackingId() {
		return trackingId;
	}

	/**
	 * 设置跟踪号码
	 * @param trackingId 跟踪号码
	 */
	public void setTrackingId(String trackingId) {
		this.trackingId = trackingId;
	}

	/**
	 * 获取送货地址
	 * @return 返回送货地址
	 */
	public String getAddress() {
		return address;
	}

	/**
	 * 设置送货地址
	 * @param address 送货地址
	 */
	public void setAddress(String address) {
		this.address = address;
	}
}
